package com.zhejiangzhengyuan.municipal_common.utils.LED;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class URLUtils {

    @Value("${road.ip}")
    private  String ip;

    @Value("${road.port}")
    private  String port;

    private static final String http = "http://";

    //todo 获取设备信息 （查询）
    private static final String url_deviceMain = "/ListenSdkService/v1.0.0/deviceMain";


    //todo 获取设备心跳 （查询）
    private static final String url_heartBeat = "/ListenSdkService/v1.0.0/deviceHeartBeatList";


    //todo 发送数据 URL (post请求)
    private static final String url_sendDataURL = "/ListenSdkService/sdk/lsPublishProgram.fgl";

    //todo 查询任务进度 （查询）
    private static String url_TaskProgressURL = "/ListenSdkService/v1.0.0/deviceTaskUpdateList";

    //todo 发送任务数据 （查询）
    private static String url_sendTask = "/ListenSdkService/sdk/lsPublishTask.fgl";


    //todo 在内存中加载，提高性能
    private static ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap();

    /**
     * 查询设备URL
     *
     * @return
     */
    public  String GetDeviceMainURL() {
        StringBuffer bf = new StringBuffer();
        bf.append(http).append(ip).append(":").append(port).append(url_deviceMain);
        if (concurrentHashMap.get("DeviceMainURL") == null) {
            concurrentHashMap.put("DeviceMainURL", bf.toString());
        }
        return concurrentHashMap.get("DeviceMainURL");
    }


    /**
     * 查询设备心跳URL
     *
     * @return
     */
    public  String GetHeartBeatURL() {
        StringBuffer bf = new StringBuffer();
        bf.append(http).append(ip).append(":").append(port).append(url_heartBeat);
        if (concurrentHashMap.get("HeartBeatURL") == null) {
            concurrentHashMap.put("HeartBeatURL", bf.toString());
        }
        return concurrentHashMap.get("HeartBeatURL");
    }


    /**
     * 发送数据 URL
     *
     * @return
     */
    public  String GetsendDataURL() {
        StringBuffer bf = new StringBuffer();
        bf.append(http).append(ip).append(":").append(port).append(url_sendDataURL);
        if (concurrentHashMap.get("SendDataURL") == null) {
            concurrentHashMap.put("SendDataURL", bf.toString());
        }
        return concurrentHashMap.get("SendDataURL");
    }

    /**
     *
     * 查询任务进度 URL
     *
     * @return
     */
    public  String GetTaskProgressURL() {
        StringBuffer bf = new StringBuffer();
        bf.append(http).append(ip).append(":").append(port).append(url_TaskProgressURL);
        if (concurrentHashMap.get("TaskProgressURL") == null) {
            concurrentHashMap.put("TaskProgressURL", bf.toString());
        }
        return concurrentHashMap.get("TaskProgressURL");
    }


    /**
     *
     * 发送任务 URL
     *
     * @return
     */
    public  String GetSendTaskURL() {
        StringBuffer bf = new StringBuffer();
        bf.append(http).append(ip).append(":").append(port).append(url_sendTask);
        if (concurrentHashMap.get("SendTaskURL") == null) {
            concurrentHashMap.put("SendTaskURL", bf.toString());
        }
        return concurrentHashMap.get("SendTaskURL");
    }


}
